package com.xuxin.baby.model;

import com.blankj.utilcode.util.LogUtils;
import com.xuxin.baby.bean.BaseBean;
import com.xuxin.baby.bean.CategoryBean;
import com.xuxin.baby.contract.CategoryContract;
import com.xuxin.baby.network.Retrofit;
import com.xuxin.baby.network.RetrofitApi;
import com.xuxin.baby.network.myObserver;
import com.xuxin.baby.presenter.CategoryPresenter;

import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
import io.reactivex.rxjava3.annotations.NonNull;
import io.reactivex.rxjava3.observers.DisposableObserver;
import io.reactivex.rxjava3.schedulers.Schedulers;
import okhttp3.ResponseBody;
import retrofit2.HttpException;

/**
 * Created by xu_xin
 * Created on 2020/10/22 0022
 * 早教分类/保健分类
 */
public class CategoryModel implements CategoryContract.Model {
    @Override
    public void getCategory(CategoryPresenter presenter, String tenantId, String token, String layout, String parentId) {
        Retrofit.getInstance().createReq(RetrofitApi.class)
                .getCategory(tenantId, token, "1", layout, parentId)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new myObserver<CategoryBean>() {
                    @Override
                    public void onNextX(CategoryBean categoryBean) {
                        if (categoryBean.isSuccess()) {
                            presenter.onSuccess(categoryBean);
                        } else {
                            presenter.onError(categoryBean);
                        }
                    }

                    @Override
                    public void onError(BaseBean baseBean) {
                        presenter.onError(baseBean);
                    }

                    @Override
                    public void onError(@NonNull Throwable e) {
                        presenter.onError(null);
                    }

                    @Override
                    public void onComplete() {
                        presenter.onComplete();
                    }
                });
    }
}